{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "\"\"\"\n",
    "Align 2 shapes and for each vertex of the first draw\n",
    "and arrow to the closest point of the second.\n",
    "The source transformation is accessible with getTransform()\n",
    "rigid=True doesn't allow scaling\n",
    "\"\"\"\n",
    "from vedo import *\n",
    "\n",
    "embedWindow(\"ipyvtk\") # or panel, k3d, itk, ipyvtk, or False\n",
    "\n",
    "plt = Plotter()\n",
    "\n",
    "limb = plt.load(datadir + \"270.vtk\")\n",
    "rim  = plt.load(datadir + \"270_rim.vtk\").c(\"r\").lw(4)\n",
    "\n",
    "arim = rim.alignTo(limb, rigid=True).c(\"g\").lw(5)\n",
    "plt += arim\n",
    "\n",
    "d = 0\n",
    "for p in arim.points():\n",
    "    cpt = limb.closestPoint(p)\n",
    "    d += mag2(p - cpt)  # square of residual distance\n",
    "\n",
    "printc(\"ave. squared distance =\", d / arim.N(), c=\"g\")\n",
    "printc(\"vtkTransform is available with getTransform():\\n\", end=\"\")\n",
    "printc([arim.getTransform()], invert=True)\n",
    "plt.show(axes=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "plt.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
